package com.faintlight.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

@Data
@Entity
@Table(name = "capsule")
public class Capsule {

    public enum Status {
        LOCKED(0, "🔒锁定中"),
        UNLOCKED(1, "🎉已解锁");

        private final int code;
        private final String display;

        Status(int code, String display) {
            this.code = code;
            this.display = display;
        }
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 50)
    private String title;

    @Column(columnDefinition = "TEXT", nullable = false)
    private String content;

    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
    @Column(nullable = false)
    private LocalDateTime unlockTime;

    @Enumerated(EnumType.ORDINAL)
    @Column(nullable = false)
    private Status status = Status.LOCKED;

    @CreationTimestamp
    @Column(updatable = false)
    private LocalDateTime createdAt;

    @ManyToOne
    @JoinColumn(name = "user_id")
    private User createdBy;

    // 新增：接收人信息
    @Column(length = 100)
    private String recipientName;

    @Column(length = 255)
    private String imageUrl;

    private Integer temperature;

    public String getDisplayStatus() {
        return status.display;
    }

}